package com.hdu.clj.fitness

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader

class DayDatabaseUtil {

    private fun getUserBase(context: Context):SQLiteDatabase{

        var ver = 1
        if (load(context,"ver").isNotEmpty()){
            ver = load(context,"ver").toInt()
        }
        val curUserName = load(context,"userName")

        //用户总数据表
        val dbDayNum = DayNumDatabase(context,"Fit.db",ver,"abc"+curUserName)
        val dbDay = dbDayNum.writableDatabase

        return dbDay
    }

    private fun load(context: Context,data:String): String {
        val content = StringBuilder()

        try {
            val input = context.openFileInput(data)
            val reader = BufferedReader(InputStreamReader(input))
            reader.use {
                reader.forEachLine {
                    content.append(it)
                }
            }
        }catch (e: IOException){
            e.printStackTrace()
        }
        return content.toString()
    }

}